<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 *      home.php
 *      
 *      Updated by : tuanhnm
 *      
 */

	class  Home  extends  CI_Controller{
	
		$lang = array('english', 'vietnamese');
		function  Home(){
			
			//parent::CI_Controller();
			parent::CI_Controller();				
			
		}
			
		/* ---------------------------------------------------
		 * Overriding base construct
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Load default setting to this controller.
		 * Parameters : void
		 * Return : void
		 * Access : privated		
		 * 
		 * */ 
		function __construct(){
			
			// References base construct function
			parent::__construct();			
				
			// -----------------------------------------------------------			
			// Load default (messages/resouces 's title) to pages
			// NOTE : must be placed in here
			// -----------------------------------------------------------
			
			// Get language from session
			$s_language_mode = $this->session->userdata('current_language');
			
			// Check session is exist 
			$language_mode = (!$s_language_mode) ? $this->config->item('default_language') : $s_language_mode;
			
			//echo ($language_mode);
			
			
			// Load message with vietnamese language, it store at folder : application/language/vietnamese/messages_lang.php
			$this->lang->load('messages',$language_mode);

			// Load message with vietnamese language to use in recaptcha, it store at folder : application/language/vietnamese/recaptcha_lang.php
			
			$this->lang->load('recaptcha',$language_mode);

			//$this->lang->load('recaptcha','vietnamese');

						
			// Load recaptcha library with vietnamese language
			//$this->load->library('recaptcha', array('lang'=>'vietnamese'));
			
			// Load form_validation library to validation fo form
			$this->load->library('form_validation');
			
			// Load pagination library to control paging
			$this->load->library('pagination');
			
			// Load user_agent library to get client user
			$this->load->library('user_agent');
			
			// Load url library
			$this->load->helper('url');
			
			// Load home model
			$this->load->model('home_model');
			
			
		}
		
		/* ---------------------------------------------------
		 * Refresh functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ refresh pages
		 * Parameters : void
		 * Return : void
		 * Access : public		
		 *  
		 * */ 
		function refresh_pages()
		{
			// If input text null to search full
			 $l_request_type = $this->input->post('ref_types', TRUE) ;
			
			switch ($l_request_type)
			{
				case ONLINE_REQ_MODE: 
					echo  $this->session->get_users_online();
					break;
				case LANG_EN_REQ_MODE:
					$this->session->set_userdata('current_language', EN_MESSAGES);
					//redirect('index.php/home/index/#background');
					break;
				default :
					break;
			}
			 
			
		}
		
		/* ---------------------------------------------------
		 * Index functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Load default dom html web.
		 * Parameters : void
		 * Return : void
		 * Access : public		
		 *  
		 * */ 
		function index(){
			
			$main_slide_url = $this->config->item('fd_main_slide_url');	
			
			$main_slide_data= $this->_get_multimedias_folders($main_slide_url, 'jpg|png|jpeg');

			// Pass content's index to data arrays
			$result = $this->home_model->get_module_content(INDEX_MODULE_PAGE, VN);		
			
			// Pass content's hotlint
			$hotline = $this->home_model->get_module_content(HOTLINE_MODULE_PAGE, VN);	
			
			$visitors = $this->home_model->get_counter_by_id(VISITORS_MODE, VN);
			
			$online = $this->home_model->get_counter_by_id(ONLINES_MODE, VN);
			
			// Check current language is vietnamese/english to select content to output
			$content_index = empty($result) ? $this->lang->line('lmg_index_content_empty') : $result['module_content'];	
			
			$l_hotline_title = empty($hotline) ? $this->lang->line('lmg_hotline_title_empty') : $hotline['name'];
			
			$l_hotline_content = empty($hotline) ? $this->lang->line('lmg_hotline_content_empty') : $hotline['module_content'];
			
			$l_total_visitors = ($visitors['error'] == SUCCESS_MODE) ? $visitors['item']['name'] :  $this->lang->line('lmg_visitors_empty');
			
			$l_num_visitors = ($visitors['error'] == SUCCESS_MODE) ? $visitors['item']['content'] :  $this->lang->line('lmg_visitors_nums_empty');
			
			$l_online = ($online['error'] == SUCCESS_MODE) ? $online['item']['name'] :  $this->lang->line('lmg_online_empty');
			
			$l_num_online=  $this->session->get_users_online();
			
			// Get page content 's index 
			$data['main_content'] =INDEX_GUEST_VIEW;
			
			// Pass content index into data arra
			$data['index_page_content'] = $content_index;
			
			$data['images_main_slide'] = $main_slide_data;
			
			$data['hotline_title'] = $l_hotline_title;
			
			$data['hotline_content'] = $l_hotline_content;
			
			$data['total_visitors'] = $l_total_visitors;
			
			$data['total_nums'] = $l_num_visitors;
			
			$data['online'] = $l_online;
			
			$data['online_nums'] = $l_num_online;
			
			// Load template 's guest and passed url 's index guest page to load content
			$this->load->view('templates/guest/template', $data);
			
		}
		
		/* ---------------------------------------------------
		 * Contactus functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Control actions on Contact us pages.
		 * Parameters : void
		 * Return : void
		 * Access : public		
		 *  
		 * */ 
		function contactus(){

			// Get page content 's contact us 
			$data['main_content'] = 'guest/contact_us';
			
			// Load template 's guest and passed url 's contact us guest page to load content
			$this->load->view('templates/guest/template', $data);
			
		}
		
		/* ---------------------------------------------------
		 * Paging Images functions
		 * ---------------------------------------------------
		 * Object : 		
		 * Parameters : 
		 * Return : 
		 * Access : public		
		 *  
		 * */ 
		 function paging_image($type=NULL, $offset_image=NULL)
		 {	
			 // Get offset_image at segment(4)
			 $l_offset_images = empty($offset_image) ? 0 : $offset_image ; 
			 
			 // Assign l_type to store product id 
			 $l_type = $type;
			 
			 // Update image 's data with new offset_images
			 $obj_images = $this->home_model->get_images_by_proid($l_type, $l_offset_images);	
			 
			 // Create images links
			$images_config['base_url'] = 'home/paging_image/'.$l_type.'/';
			$images_config['total_rows'] = $this->home_model->get_total_items_by_proid($l_type, IMAGE_TABLES);
			$images_config['per_page'] = $this->config->item('images_per_page');
			$images_config['uri_segment'] = 4;
			$this->pagination->initialize($images_config);
			
			$image_links = $this->pagination->create_links();;
			
			// Type 's data to description production 
			$data['type'] = $l_type;
			
			// Image 's data
			$data['images'] = $obj_images; 
			
			// Link 's data
			$data['images_link'] = $image_links; 

     		 // Pass data into load view PICTURES_GUEST_VIEW
			 $this->load->view(PICTURES_GUEST_VIEW, $data);
		 }
		 
		 /* ---------------------------------------------------
		 * Paging Videos functions
		 * ---------------------------------------------------
		 * Object : 		
		 * Parameters : 
		 * Return : 
		 * Access : public		
		 *  
		 * */ 
		 function paging_video($type=NULL, $offset_video=NULL)
		 {					 	
			 // Get offset_image at segment(4)
			 $l_offset_videos = empty($offset_video) ? 0 : $offset_video ; 
			 
			 // Assign l_type to store product id 
			 $l_type = $type;
			 
			 // Update video 's data with new offset_images
			 $obj_videos = $this->home_model->get_videos_by_proid($l_type, $l_offset_videos);	
			 
			 // Create images links
			$images_config['base_url'] = 'home/paging_video/'.$l_type.'/';
			$images_config['total_rows'] = $this->home_model->get_total_items_by_proid($l_type, IMAGE_TABLES);
			$images_config['per_page'] = $this->config->item('images_per_page');
			$images_config['uri_segment'] = 4;
			$this->pagination->initialize($images_config);
			
			$video_links = $this->pagination->create_links();
			
			// Type 's data to description production 
			$data['type'] = $l_type;
			
			// Image 's data
			$data['videos'] = $obj_videos; 
			
			// Link 's data
			$data['videos_link'] = $video_links; 

     		 // Pass data into load view PICTURES_GUEST_VIEW
			 $this->load->view(VIDEOS_GUEST_VIEW, $data);
		 }
		 
		 /* ---------------------------------------------------
		 * View contact content page functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Use to view contact 's content.
		 * Parameters : 
		 * Return : 		
		 * Access : private		
		 *  
		 * */ 
		 function _view_contact_content()
		 {
			
			 //$this->load->library('recaptcha', array('lang'=>'vietnamese'));
			 
			 // Get content of contact 's module , load from home_model
			$result = $this->home_model->get_module_content(CONTACT_MODULE_PAGE, VN);					
			
			// Check current language is vietnamese/english to select content to output
			$contact_content = empty($result) ? $this->lang->line('lmg_index_content_empty') : $result['module_content'];		
			 		  
			 // Content of contact to pass Contact Us View
			 $data['contact_content'] = $contact_content;
			 
			 // Get captcha
			 /*
			 if($this->recaptcha->get_html() != ""){
				$data['recaptcha'] = $this->recaptcha->get_html();
			 }
			 */
			 //$data['recaptcha'] = recaptcha();
			 //echo $data['recaptcha'];
			// Check form is submit
			 /*
			 * Validate data
			 * 
			 */ 
		
			$this->form_validation-> set_rules('name', $this->lang->line('lang.i18n.messages.contact.name'), 'required|xss_clean');
			//$this->form_validation-> set_rules('address', $this->lang->line('lang.i18n.messages.contact.address'), 'xss_clean');
			$this->form_validation-> set_rules('email', $this->lang->line('lang.i18n.messages.contact.email'), 'required|valid_email|xss_clean');
			//$this->form_validation-> set_rules('phone', $this->lang->line('lang.i18n.messages.contact.phone'), 'xss_clean');
			$this->form_validation-> set_rules('content', $this->lang->line('lang.i18n.messages.contact.comment'), 'required|xss_clean');
			 // Load contact view
			 //$this->form_validation-> set_rules('captcha', 'captcha', 'required|xss_clean');

			 if (!$this->form_validation->run())
			 {
				$this->load->view(CONTACT_GUEST_VIEW, $data);
			 }else{
				//echo $this->session->userdata('captcha');
				//return;
				/*
				if($this->input->post('captcha')!= ""){
					
					if ($this->session->userdata('captcha') || trim(strtolower($this->input->post('name'))) != $this->session->userdata('captcha')) {
						$this->form_validation->set_message('captcha',$this->lang->line('recaptcha_incorrect_response'));
						$captcha = htmlspecialchars($this->input->post('name'));
						unset($_SESSION['captcha']);
						
						$this->load->view(CONTACT_GUEST_VIEW, $data);
						return;
					}
				}
				*/
				$name = $this->input->post('name');
				$email = $this->input->post('email');
				$address = $this->input->post('address');
				$phone = $this->input->post('phone');
				$content = $this->input->post('content');
				$this->insert($name, $address, $email, $phone, $content);
				$data['message'] = "Gửi thành công";
				$this->load->view(CONTACT_GUEST_VIEW, $data);
			 }
			 
		 }
		
		
		/* ---------------------------------------------------
		 * View index content page functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Use to view index 's content.
		 * Parameters : 
		 * Return : 		
		 * Access : private		
		 *  
		 * */ 
		 function _view_index_content()
		 {
			   // Pass content's index to data arrays
			  $result = $this->home_model->get_module_content(INDEX_MODULE_PAGE, VN);		
				
			  // Check current language is vietnamese/english to select content to output
			  $content_index = empty($result) ? $this->lang->line('lmg_index_content_empty') : $result['module_content'];			
			  
			  // Pass content index into data array
			  $data['index_page_content'] = $content_index;
			  
			  $this->load->view(INDEX_GUEST_VIEW, $data);
		 }
		
		/* ---------------------------------------------------
		 * View Product List functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Use to view load image's list and video's list of product item .
		 * Parameters : 
		 * 		+ $type : nums to define product id
		 * 		+ $default_offset_image : nums to define current offset 's image
		 * 		+ $default_offset_video : nums to define current offset's video
		 * Return : 		
		 * Access : private		
		 *  
		 * */ 
		 function _view_product_list($type=NULL, $offset_images=NULL, $offset_videos=NULL)
		 {
			 $l_offset_images = empty($offset_images) ? 0 : $offset_images;
			 
			 $l_offset_videos = empty($offset_videos) ? 0 : $offset_videos;
			 
			 $l_type = $type;

			 // Define title to product view detail - to get data from database where language 's current session			
			$l_result = $this->home_model->get_product_name($l_type, VN);
			
			$data['pro_name'] = $l_result['product_name'];
			
			// Get object images 's cable tray
			$obj_images = $this->home_model->get_images_by_proid($l_type, $l_offset_images);														
			
			// Get object videos 's cable tray
			$obj_videos = $this->home_model->get_videos_by_proid($l_type, $l_offset_videos);

			// Create images links
			$images_config['base_url'] = 'home/paging_image/'.$l_type.'/';
			$images_config['total_rows'] = $this->home_model->get_total_items_by_proid($l_type, IMAGE_TABLES);
			$images_config['per_page'] = $this->config->item('images_per_page');
			$images_config['uri_segment'] = 4;
			$this->pagination->initialize($images_config);
			
			$image_links = $this->pagination->create_links();
							
			
			// Create videos links
			$videos_config['base_url'] = 'home/paging_video/'.$l_type.'/';
			$videos_config['total_rows'] = $this->home_model->get_total_items_by_proid($l_type, VIDEO_TABLES);
			$videos_config['per_page'] = $this->config->item('videos_per_page');
			$images_config['uri_segment'] = 4;
			$this->pagination->initialize($videos_config);
			
			$video_links = $this->pagination->create_links();
			
			// Pass videos_name components with define VIDEOS_GUEST_VIEW store at constant.php
			$data['video_components'] = VIDEOS_GUEST_VIEW;
			
			// Pass pictures_name components with define PICTURES_GUEST_VIEW store at constant.php
			$data['picture_components'] = PICTURES_GUEST_VIEW;
					
			// Pass object images into data
			$data['images'] = $obj_images;
												
			// Pass object videos into data
			$data['videos'] = $obj_videos;
			
			// Pass image link into data
			$data['images_link'] = $image_links;
			
			// Pass video link into data
			$data['videos_link'] = $video_links;
			
			// Type 's data to description production 
			$data['type'] = $l_type;
			
			$this->load->view('guest/products', $data);
		 }
		 
		 /* ---------------------------------------------------
		 * View functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Control select page view .
		 * Parameters : 
		 * 		+ pages : nums to select page view
		 * Return : 
		 * 		+ html fragments
		 * Access : public		
		 *  
		 * */ 
		 function view($page=NULL, $offset_images=NULL, $offset_videos=NULL)
		 {
			 			 			
			 $l_offset_images = (empty($offset_images) || !is_numeric($offset_images))? 0 : $offset_images;
			 
			 $l_offset_videos = (empty($offset_videos) || !is_numeric($offset_videos)) ? 0 : $offset_videos;
			 
			 $l_page = (empty($page) || !is_numeric($page)) ? INDEX_PAGE : $page;
			
			 switch($l_page)
			 {
				 case CABLE_TRAY_PAGE: // if page is cable tray	

					$this->_view_product_list($l_page, $l_offset_images, $l_offset_videos); // Load product list		
					break;
				 case TRUNKING_PAGE: // if page is trunking
					
					$this->_view_product_list($l_page, $l_offset_images, $l_offset_videos); // Load product list
					break;
				 case U_CHANNEL_PAGE: // if page is U Channel
					
					$this->_view_product_list($l_page, $l_offset_images, $l_offset_videos); // Load product list
					break;
				 case SLIDE_LADDER_PAGE: // if page is Slide Ladder
					
					$this->_view_product_list($l_page, $l_offset_images, $l_offset_videos); // Load product list
					break;
				 case DE_COILER_PAGE: // if page is De coiler
					
					$this->_view_product_list($l_page, $l_offset_images, $l_offset_videos); // Load product list
					break;
				 case CONTACT_US_PAGE : // if page is contact us
					  
					  $this->_view_contact_content();
					  break;
				 default : // default is index page					  					
					 $this->_view_index_content();
					  break;
			 }
		 }
		 
		/* ---------------------------------------------------
		 * small_imaging functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ return dom small_imaging .
		 * Parameters : 
		 * 		+ offset : current ofsset (default 0)
		 * Return : 
		 * 		+ html fragments
		 * Access : public		
		 *  
		 * */ 
		 function small_imaging($offset=0)
		 {
			 // Get image from small image folder
			$sub_slide_url = $this->config->item('fd_sub_slide_url');	
			
			$sub_slide_data= $this->_get_multimedias_folders($sub_slide_url, 'jpg|png|jpeg');

			// images per pages 
			$limit = $this->config->item('small_images_per_page');
			
			$l_offset = $offset;
			
			// total images in subslide folder
			$total_small_images = count($sub_slide_data['images']);
			
			 // Create sub slide default links
			$sub_slide_config['base_url'] = 'home/small_imaging/';
			$sub_slide_config['total_rows'] = $total_small_images;
			$sub_slide_config['per_page'] = $limit;
			$sub_slide_config['uri_segment'] = 3;
			$this->pagination->initialize($sub_slide_config);
			
			$sub_slide_links = $this->pagination->create_links();		
			
			$child_sub_slide_data = $this->home_model->get_items_array($sub_slide_data['images'], $l_offset, $limit);
			
			$data['small_slide_images'] = $child_sub_slide_data;
			
			$data['smaill_slide_links'] = $sub_slide_links;
			
			$this->load->view(SMALL_SLIDE_IMAGE_VIEW, $data);			
		 }
		
		/* ---------------------------------------------------
		 * Product_details functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ View product detail  .
		 * Parameters : 
		 * 		+ id : product id
		 * Return : 
		 * 		+ html fragments
		 * Access : public		
		 *  
		 * */ 
		function product_detail($product_id=NULL, $image_id=NULL)
		{
			// Check if product_id empty
			if (empty($product_id) || empty($image_id)) 
			{
				
				echo $this->lang->line('lmg_product_detail_vars_valid');
				
				return;
			}
			
			$l_product_id = $product_id;
			
			$l_image_id = $image_id;
			
			$l_product_content = $this->home_model->get_product_content($l_product_id, VN);
			
			$l_large_image_url = $this->home_model->get_image_by_proid_id($l_product_id, $l_image_id, VN);
			
			// Get image from small image folder
			$sub_slide_url = $this->config->item('fd_sub_slide_url');	
			
			$sub_slide_data= $this->_get_multimedias_folders($sub_slide_url, 'jpg|png|jpeg');

			// images per pages 
			$limit = $this->config->item('small_images_per_page');
			
			// default offset
			$offset = 0;
			
			// total images in subslide folder
			$total_small_images = count($sub_slide_data['images']);
		
			 // Create sub slide default links
			$sub_slide_config['base_url'] = 'home/small_imaging/';
			$sub_slide_config['total_rows'] = $total_small_images;
			$sub_slide_config['per_page'] = $limit;
			$sub_slide_config['uri_segment'] = 3;
			$this->pagination->initialize($sub_slide_config);
			
			$sub_slide_links = $this->pagination->create_links();		
			
			$child_sub_slide_data = $this->home_model->get_items_array($sub_slide_data['images'], $offset, $limit);
			
			// Get id from GET method/parameters
			$data['pro_id'] = is_null($product_id) ? 'Unkown' : $product_id;
			
			$data['title_product'] =  $l_large_image_url['image_name'];			
			
			$data['content_product'] = $l_product_content['product_content'];
			
			$data['title_link_back_to'] = $this->lang->line('lmg_title_link_back_to_pictures');		
			
			$data['large_image_url']	= $l_large_image_url['image_url'];
			
			$data['small_slide_components'] = SMALL_SLIDE_IMAGE_VIEW;
			
			$data['small_slide_images'] = $child_sub_slide_data;
			
			$data['smaill_slide_links'] = $sub_slide_links;
			
			// Load product_detail components
			$this->load->view(PRODUCT_DETAIL_GUEST_VIEW, $data);
		}
		
		/* ---------------------------------------------------
		 * Video_details functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ View , play video detail  .
		 * Parameters : 
		 * 		+ id : product id
		 * Return : 
		 * 		+ html fragments
		 * Access : public		
		 *  
		 * */ 
		 function video_detail($product_id=NULL, $video_id=NULL)
		 {
			 
			 // Check if product_id empty
			if (empty($product_id) || empty($video_id)) 
			{
				
				echo $this->lang->line('lmg_product_detail_vars_valid');
				
				return;
			}
			
			$l_product_id = $product_id;
			
			$l_video_id = $video_id;
			
			$l_video_obj = $this->home_model->get_video_by_proid_id($l_product_id, $l_video_id, VN);
			
			// Check if video obj is empty (no data with product id & video id), so return failed message 
			if (empty($l_video_obj))
			{
				
				echo $this->lang->line('lmg_video_detail_data_empty');
				
				return;
			}
			 
			 // Get id from GET method/parameters
			$data['video_title'] = $l_video_obj['video_name'];
			
			$data['video_url'] = $l_video_obj['video_url'];
			
			$data['title_link_back_to'] = $this->lang->line('lmg_title_link_back_to_videos');
			
			// Load product_detail components
			$this->load->view(VIDEO_DETAIL_GUEST_VIEW, $data);
		 }		
		 
		 /* ---------------------------------------------------
		 * Search_result functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Response search 's result  .
		 * Parameters : 
		 * 		+ Search_String : string to search
		 * Return : 
		 * 		+ html fragments
		 * Access : public		
		 *  
		 * */  
		 function search_result($search=NULL)
		 {
			 // Validate .search_form .search_text input text from post method, if avoid xxs attack
			 
			 // If input text null to search full
			 $l_search_string = $this->input->post('query', TRUE) ;

			 $l_search_string = empty($l_search_string) ? SEARCH_FULL : $l_search_string;
			 
			 // Get current language 's state (VN or EN)
			 $l_language_type = VN;
			 
			 // Get total images per page on search result from config
			 $l_images_per_search_page = $this->config->item('images_per_search_page');
			 
			 // Get total videos per page on search result from config
			 $l_videos_per_search_page = $this->config->item('videos_per_search_page');
			 
			 // Set images_offset default (has value 0)
			 $l_default_offset_image = DEFAULT_OFFSET_IMAGES_SEARCH;
			 
			 // Set videos_offset default (has value 0)
			 $l_default_offset_video = DEFAULT_OFFSET_VIDEOS_SEARCH;
			 
			 // Get images data from Image table with name begin contain l_search string and language by calling home_model , remind sorting by Alphabeta
			 $l_images = $this->home_model->get_images_by_name($l_search_string, $l_language_type, $l_default_offset_image, $l_images_per_search_page, CONTAIN_CHAR_MODE);
			 
			 // Get videos data from Video table with name begin contain l_search string and language by calling home_model , remind sorting by Alphabeta			 			
			 $l_videos = $this->home_model->get_videos_by_name($l_search_string, $l_language_type, $l_default_offset_video, $l_videos_per_search_page, CONTAIN_CHAR_MODE);
			 
			// Create images links
			$images_config['base_url'] = 'home/paging_search_image/';
			$images_config['total_rows'] = $l_images['total'];
			$images_config['per_page'] = $l_images_per_search_page;
			$images_config['uri_segment'] = 3;
			$this->pagination->initialize($images_config);
			
			$image_links = $this->pagination->create_links();
						
			
			// Create videos links
			$videos_config['base_url'] = 'home/paging_search_video/';
			$videos_config['total_rows'] = $l_videos['total'];
			$videos_config['per_page'] = $l_videos_per_search_page;
			$images_config['uri_segment'] = 3;
			$this->pagination->initialize($videos_config);
			
			$video_links = $this->pagination->create_links();
			 
			 // Get id from GET method/parameters
			 $data['search_title'] = $this->lang->line('lmg_title_search_result').$l_search_string;
			 
			 $data['images_title'] = $this->lang->line('lmg_image_title_search_result').' ('.$l_images['total'].')';
			 
			 $data['image_search_result'] = IMAGE_SEARCH_RESULT_VIEW;
			 
			 $data['images'] = $l_images['items'];
			 
			 $data['images_message'] = $this->lang->line('lmg_image_empty_search_result');
			 
			 $data['images_paging'] = $image_links;
			 
			 $data['videos_title'] =$this->lang->line('lmg_video_title_search_result').' ('.$l_videos['total'].')';
			 
			 $data['video_search_result'] = VIDEO_SEARCH_RESULT_VIEW;
			 
			 $data['videos'] = $l_videos['items'];
			 
			 $data['videos_message'] = $this->lang->line('lmg_video_empty_search_result');
			 
			 $data['videos_paging'] = $video_links;
			
			// Load product_detail components
			$this->load->view(SEARCH_RESULT_VIEW, $data);
		 }
		 
		/* ---------------------------------------------------
		 * Get Multi folders functions
		 * ---------------------------------------------------
		 * Object : 
		 * 		+ Read images from folder to return image 's array  .
		 * Parameters : 
		 * 		+ Path_folders : folder 's path which store images 
		 * 		+ Filter_files : ext file to read
		 * Return : 
		 * 		+ images 's array
		 * Access : private
		 *  
		 * */  
		 function _get_multimedias_folders ($folder_path=NULL, $filter_files=NULL)
		 {
			$result = array (
					 'images' => array(),
					 'is_error' => false,
					 'message' => ''					 
			 );
			 
			 // Check parameters is empty , TRUE to returned NULL
			 if (empty($folder_path) || empty($filter_files))
			 {
				 
				 $result['is_error'] = true;
				 $result['message'] = $this->lang->line('lmg_parameter_read_empty');
				 
				 return $result;
			 }
			 
			 $l_folder_path = $folder_path;
			 
			 $l_filter_files = $filter_files;
			 
			// Check folder_path is exists, FALSE to returned NULL
			if (! is_dir($l_folder_path))
			{
 
				 $result['is_error'] = true;
				 $result['message'] = $this->lang->line('lmg_folders_not_exists');
				 
				 return $result;
			}
			
			$dh = opendir($l_folder_path);
			
			// Check rules open foler_path, FALSE to returned NULL
			if (!$dh)
			{	 
				 $result['is_error'] = true;
				 $result['message'] = $this->lang->line('lmg_folders_not_open');
				 
				 return $result;
			}
			
			$i = 0;
			
			// Read each file in folder_path
			while (($file = readdir($dh)) !== false) {
					
					// get file extension
					$ext = strrev(strstr(strrev($file), ".", TRUE));
					
					if ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png') {
						
						$result['images'][$i] = $file;
					
						$i++;
					}
					
			}
			
			closedir($dh);					
			
			$result['message'] = $this->lang->line('lmg_load_images_folder_success');
			
			return $result;
		 }			
		 
		 function test($page=NULL, $offset_1=NULL, $offset_2=NULL)
		 {
			 /*
			$client_ip = $this->input->ip_address();
			$computer_name = $this->agent->browser().' - version : '.$this->agent->version();
			$time = $this->agent->agent_string();
			
			$data = array(
				'client_ip' => $client_ip, 
				'computer_name' => $computer_name, 
				'time' => $time);
				
			print_r ($data);
			* */
			
			$users_online_count = $this->session->get_users_online();
			
			echo ('users_online : ' . $users_online_count);
		}
		
<<<<<<< .mine
=======
		function insert($name = "", $address = "", $email = "", $phone = "", $content = ""){
			$sql = "INSERT INTO  `contact` (name, address, email, phone, content) VALUES (?, ?, ?, ?, ?)";
			
			$query = $this->db->query($sql, array($name, $address, $email, $phone, $content));
			}
>>>>>>> .r43
		 
		
	}
?>
